import { Dispatch,AnyAction} from 'redux'
import * as actionTypes from '../constants'
import {
    getIconsRequest, 
    getRankLikeRequest,
    getSwiperRequest,
    getRelevantRequest,
    getRelevantARequest,
    getkeypointsRequest,
    getCityRequest,
    getRelationRequest,
} from '@/api/request'

// 页面级别action  
// promise.all 
export const changeLoading = (data: boolean) => ({
    type: actionTypes.CHANGES_LOADING,
    data
})

export const changeTabIcons = (data:any[]) => ({
    type: actionTypes.Tab_ICONS,
    data
})

export const getTabIcons = () => {
    return (dispatch:Dispatch) => {
       (async () => {
        let {data} = await getIconsRequest()
        // console.log(data)
        dispatch(changeTabIcons(data))
       })()
    }
}
export const changeRankLike = (data:any[]) => ({
    type: actionTypes.CHNAGE_RANK_LIKE,
    data
})

export const getTabRankLike  = () => {
    return (dispatch:Dispatch) => {
       (async () => {
        let {data} = await getRankLikeRequest()
        // console.log(data
        dispatch(changeRankLike(data))
       })()
    }
}

export const changeInputValue = (data:{}) => {
    // console.log(data);
    return {type: actionTypes.CHANGE_INPUT_VALUE,
        data}
} 
export const changeSwiper = (data:any[]) => ({
    type: actionTypes.CHANGE_SWIPER,
    data
})
export const getSwiper = () => {
    return (dispatch:Dispatch) => {
        (async () => {
            let {data} = await getSwiperRequest()
            dispatch(changeSwiper(data))
            console.log(data)
        })()
    }
}
export const changeRelevant = (data:any[]) => ({
    type: actionTypes.CHANGE_RELEVANT,
    data
})
export const getRelevant = () => {
    return (dispatch:Dispatch) => {
        (async () => {
            let {data} = await getRelevantRequest()
            dispatch(changeRelevant(data))
            // console.log(data)
        })()
    }
}
export const getRelevantA = () => {
    return (dispatch:Dispatch) => {
        (async () => {
            let {data} = await getRelevantARequest()
            dispatch(changeRelevant(data))
            // console.log(data)
        })()
    }
}
export const changeKeypoints = (data:any[]) => ({
    type: actionTypes.CHANGE_KEYPOINTS,
    data
})
export const getKeypoints = () => {
    return (dispatch:Dispatch) => {
        (async () => {
            let {data} = await getkeypointsRequest()
            dispatch(changeKeypoints(data))
            // console.log(data)
        })()
    }
}
export const changeCity = (data:any[]) => ({
    type: actionTypes.CHANGE_CITY,
    data
})
export const getCity = () => {
    return (dispatch:Dispatch) => {
        (async () => {
            let {data} = await getCityRequest()
            dispatch(changeCity(data))
            // console.log(data)
        })()
    }
}
export const changeRelation = (data:any[]) => ({
    type: actionTypes.CHANGE_RELATION,
    data
})
export const getRelation = () => {
    return (dispatch:Dispatch) => {
        (async () => {
            let {data} = await getRelationRequest()
            dispatch(changeRelation(data))
            console.log(data)
        })()
    }
}